package org.speed.spring.core.aop.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy<T> implements InvocationHandler {
	
	private T target;
	
	public JdkProxy(T target) {
		this.target = target;
	}
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		
		System.out.println("before");
		
		Object rs = method.invoke(target, args);
		
		System.out.println("after");
		
		return rs;
	}

	public T getProxy() {
		return (T) Proxy.newProxyInstance(getClass().getClassLoader(), target.getClass().getInterfaces(), this);
	}
	
}
